//
//  TPLoginViewModel.m
//  Yimei
//
//  Created by xiaowu xiaowu on 2017/12/1.
//  Copyright © 2017年 xiaowu xiaowu. All rights reserved.
//

#import "TPLoginViewModel.h"

@implementation TPLoginViewModel

-(instancetype)init{
    if(self = [super init]){
        
        _phoneSignal = RACObserve(self, phone);
        _pswSignal = RACObserve(self, psw);
        _codeSignal = RACObserve(self, code);
        _nameSignal = RACObserve(self, name);
    }
    
    return self;
}

-(RACSignal *)validSigneSignal{
    
    RACSignal *validSignal = [RACSignal combineLatest:@[_phoneSignal,_codeSignal,_pswSignal] reduce:^id _Nullable{
        return @(_phone.length >=11 && _psw.length >= 1 && _code.length >= 4);
    }];
    return validSignal;
}


-(RACSignal *)validLoginCodeSignal{
    
    RACSignal *validSignal = [RACSignal combineLatest:@[_phoneSignal,_codeSignal] reduce:^id _Nullable{
        return @(_phone.length >=11 && _code.length >= 1);
    }];
    return validSignal;
}

-(RACSignal *)validLoginSignal{
    
    RACSignal *validSignal = [RACSignal combineLatest:@[_phoneSignal,_pswSignal] reduce:^id _Nullable{
        return @(_phone.length >=11 && _psw.length >= 1);
    }];
    return validSignal;
}

@end
